module game
{
	export class BagItem extends eui.ItemRenderer
	{
		private idTxt:eui.Label;
		private shareBtn:eui.Button;

		private isReady = false;

		public constructor()
		{
			super();
			this.skinName = "resource/game_ui/BagItem.exml";
		}

		protected dataChanged(): void
		{
			this.updateUI();
		}

		private updateUI():void
		{
			if(this.idTxt)
			{
				this.idTxt.text = this.data.id + "";
				if(!this.hasEventListener(egret.TouchEvent.TOUCH_TAP))
				{
					this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onTap,this);
				}
			}
			else
			{
				egret.setTimeout(this.updateUI,this,200);
			}
		}

		private onTap(e:egret.TouchEvent):void
		{
			//分享
			if(e.target == this.shareBtn)
			{
				console.warn("分享....");
				UIManager.copyTxt(window.location.href + "?mapid=" + this.data.id);
				this.parent.dispatchEventWith(GameEvent.BagItem_Share,false,this.data);
			}
			else
			{
				console.warn("展示地图");
				// GameManager.getInstance().getMapById(this.data.id);
				this.parent.dispatchEventWith(GameEvent.BagItem_Tap,false,this.data);
			}
		}
	}
}